package com.ruoyi.user.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.user.domain.Members;
import com.ruoyi.user.service.IMembersService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 会员表Controller
 * 
 * @author ruoyi
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/members")
public class MembersController extends BaseController
{
    @Autowired
    private IMembersService membersService;

    /**
     * 查询会员表列表
     */
    @RequiresPermissions("user:members:list")
    @GetMapping("/list")
    public TableDataInfo list(Members members)
    {
        startPage();
        List<Members> list = membersService.selectMembersList(members);
        return getDataTable(list);
    }

    /**
     * 导出会员表列表
     */
    @RequiresPermissions("user:members:export")
    @Log(title = "会员表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Members members)
    {
        List<Members> list = membersService.selectMembersList(members);
        ExcelUtil<Members> util = new ExcelUtil<Members>(Members.class);
        util.exportExcel(response, list, "会员表数据");
    }

    /**
     * 获取会员表详细信息
     */
    @RequiresPermissions("user:members:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(membersService.selectMembersById(id));
    }

    /**
     * 新增会员表
     */
    @RequiresPermissions("user:members:add")
    @Log(title = "会员表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Members members)
    {
        return toAjax(membersService.insertMembers(members));
    }

    /**
     * 修改会员表
     */
    @RequiresPermissions("user:members:edit")
    @Log(title = "会员表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Members members)
    {
        return toAjax(membersService.updateMembers(members));
    }

    /**
     * 删除会员表
     */
    @RequiresPermissions("user:members:remove")
    @Log(title = "会员表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(membersService.deleteMembersByIds(ids));
    }
}
